package net.wendal.nutzbook;

import net.wendal.nutzbook.bean.User;
import net.wendal.nutzbook.service.UserService;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.integration.quartz.NutQuartzCronJobFactory;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

import java.util.Date;
/**
 * MainSetup需要实现Setup接口,并在其中初始化数据库表
 * @author dengwubo
 *
 */
public class MainSetup implements Setup{

	public void init(NutConfig nc) {
		Ioc ioc = nc.getIoc();
		Dao dao = ioc.get(Dao.class);
		Daos.createTablesInPackage(dao, "net.wendal.nutzbook", false);
		//通过Daos.migration实现表结构自动修改
		Daos.migration(dao,User.class,true,true,true);
		UserService us = ioc.get(UserService.class);
		//初始化默认根用户
		if(us.fetch("admin")==null) {
			us.add("admin", "123456");
		}
//获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
		ioc.get(NutQuartzCronJobFactory.class);





































		  // 测试发送邮件
       /* try {
            HtmlEmail email = ioc.get(HtmlEmail.class);
            email.setSubject("入职提醒");
            email.setMsg("请您记得五月四号前来入职哦！--杭州善兔信息科技有限公司");
            email.addTo("770966315@qq.com");//请务必改成您自己的邮箱啊!!!
//            email.setFrom("dengwuboob@163.com");
//            email.setSSLOnConnect(false);
  *//*          email.setHostName("smtp.163.com");
            email.setSmtpPort(25);
            email.setAuthentication("dengwuboob", "YY770966315");
            email.setDebug(true);
            email.setStartTLSEnabled(true);
            email.setStartTLSRequired(true);*//*
            email.buildMimeMessage();
            email.sendMimeMessage();
        } catch (Exception e) {
            e.printStackTrace();
        }*/
		
	}

	public void destroy(NutConfig nc) {
		
	}

}
